﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using agsXMPP;
using agsXMPP.protocol.client;

namespace xmppSpike
{
    class MyBase{}
    class MyDerivation : MyBase {}
    class MySub : MyBase {}

    class Program
    {
        static void Main(string[] args)
        {
            AutoResetEvent are = new AutoResetEvent(false);
            XmppClientConnection conn = new XmppClientConnection("tfsvs08");
            conn.OnLogin += delegate(object o)
                                {
                                    Console.WriteLine("logged in");
                                    are.Set();
                                };
            try
            {
                conn.Open("plisch", "plisch");
                are.WaitOne();
                Console.WriteLine("opened");

                conn.OnMessage += delegate(object o, Message m)
                                      {
                                          Console.WriteLine("  {0}: {1}", m.From, m.Body);
                                      };

                conn.Send(new Message("plum@tfsvs08", "hello! " + DateTime.Now.ToString()));

                Console.WriteLine("msg or empty to exit:");
                while (true)
                {
                    string text = Console.ReadLine();
                    if (text == "") break;
                    conn.Send(new Message("plum@tfsvs08", text));
                }
            }
            finally
            {
                conn.OnClose += delegate(object o)
                                    {
                                        Console.WriteLine("loggged out");
                                        are.Set();
                                    };
                conn.Close();
                are.WaitOne();
                Console.WriteLine("closed");
            }



        }
    }
}
